package com.wnxy.sddfp.trade.controller;

import com.wnxy.sddfp.common.model.dto.query.BorrowRecordQuery;
import com.wnxy.sddfp.common.model.dto.trade.BorrowRecordDTO;
import com.wnxy.sddfp.common.model.vo.borrow.BorrowRecordVo;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.common.utils.Pages;
import com.wnxy.sddfp.trade.service.IBorrowRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Docter
 * @date 2023 -07-31
 * @desc
 */
@RestController
public class TradeController {

    @Autowired
    private IBorrowRecordService borrowRecordService;

    @ApiOperation("借款申请")
    @PostMapping("/trade/borrow/add")
    public Result addBorrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO){
        borrowRecordService.addBorrowRecord(borrowRecordDTO);
        return Result.ok("借款记录成功、等待审核");

    }

    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query")
    public Result<Pages<BorrowRecordVo>> queryBorrowRecord(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "2") Integer pageSize,
            @RequestBody BorrowRecordQuery borrowRecordQuery) {
        Pages<BorrowRecordVo> pages =
                borrowRecordService.queryBorrowRecord(pageNum,pageSize,borrowRecordQuery);
        return Result.ok(pages);
    }

    @PutMapping("/trade/borrow/status")
    public Result borrowStatus(String approveStatus ,String borrowRecordId){
        String result = borrowRecordService.verifyStatus(approveStatus,borrowRecordId);
        return Result.ok(result);
    }
}
